/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager;
import br.com.deployment.entidade.registroimovel.Objeto;
import br.com.deployment.util.Caracteres;
import java.io.Serializable;
import java.net.URL;
import java.util.Iterator;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 *
 * @author Roniere Sousa
 */
@ManagedBean
@SessionScoped
public class CepWebService implements Serializable{
    
    private static final long serialVersionUID = -2766151349524323086L;
   
    private Objeto objeto;
    
    private int resultado = 0;
    private String resultado_txt = "";
    
    public CepWebService() {
        objeto = new Objeto();
    }
    
    public Objeto buscarCEP(Objeto end) {
//        Caracteres c = new Caracteres();
//        try {
//            URL url = new URL("http://maps.googleapis.com/maps/api/geocode/xml?address=rua_merval_neres_2812&sensor=true");
//            
//            Document document = getDocumento(url);
//
//            Element root = document.getRootElement();
//                    
//            for ( Iterator i = root.elementIterator(); i.hasNext(); ) {
//                Element element = (Element) i.next();
//                
//                
//                if (element.getQualifiedName().equalsIgnoreCase("uf"))
//                    end.setEstado(element.getText());                
//                
//                if (element.getQualifiedName().equals("long_name"))
//                    System.err.println("testeeeeee + "+element.getText());                
//                
//                if (element.getQualifiedName().equals("bairro"))
//                    end.setBairro(element.getText());                
//                
//                if (element.getQualifiedName().equals("tipo_logradouro"))
////                    end.setTipo_logradouro(element.getText());                
//                
//                if (element.getQualifiedName().equals("bairro"))
//                    end.setLogradouro(element.getText());                
//                           
//            }
//        }
//        catch (Exception ex) {
//            ex.printStackTrace();
//            System.out.println("ERRROOOOO");
//        }
//        
//        objeto = end;
//        System.err.println(end.getLogradouro());
        return null;
    }

    public Document getDocumento(URL url) throws DocumentException {
        SAXReader reader = new SAXReader();
        Document document = reader.read(url);
        return document;
    } 
    public void confirmaCEP(){
        
    }
 
   
    @Override
    public String toString() {
        return "CepWebService{" + "endereco=" + objeto + ", resultado=" + resultado + ", resultado_txt=" + resultado_txt + '}';
    }


    
}